<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/template.xhtml">
    <ui:define name="content">
    <h:form id="form" align="center">
    <div id="iddiv" align="center" style="width : 800px;font-size: 10pt" >
    <br />
    <p:panel id="idpanel">
    	<h:message for="medicationId"/>
    	<f:facet name="header">
    		<h:outputText value="Find Order By MedicationID" />
		</f:facet>
    	<h:panelGrid columns="3">
    				<h:outputText value="Medication Id: " />
        			<p:inputText value="#{orderInventoryBean.medicationId}" id="medicationId" required="true" />
        			<p:commandButton action="#{orderInventoryBean.findOrderMedicationByMedicationId}" value="Find by Med. Id" update="medinv,orderId" process="@this"/>
        			<p:spacer height="2"/><p:spacer height="2"/><p:spacer height="2"/>
        			<h:outputText value="Order Id: "  />
        			<p:inputText value="#{orderInventoryBean.orderId}" id="orderId" required="true" />
					<p:commandButton action="#{orderInventoryBean.findOrderMedicationByOrderId}" value="Find by Order Id" update="medinv,medicationId" process="@this"/>
        			<p:spacer height="2"/><p:spacer height="2"/><p:spacer height="2"/>
        			<h:outputText value="Click to show all open orders: "  /><p:spacer /><p:commandButton action="#{orderInventoryBean.findAllOpenOrders}" value="Show All" update="medinv,medicationId,orderId" process="@this"/>
    	</h:panelGrid>
    </p:panel>
    </div>
    <br />
    <div id="block1" align="center" style="width : 800px; font-size: 10pt" >	
    <p:panel>
        	<p:dataTable id="medinv" var="medinvs" value="#{orderInventoryBean.orderList}" style="text-align : center" paginator="true" rows="10">  
  
        		<p:column headerText="Medication Id" style="width:10%">  
            		<h:outputText value="#{medinvs.medication.medicationId}" />  
        		</p:column>  
  
        		<p:column headerText="Generic Name" style="width:40%">  
            		<h:outputText value="#{medinvs.medication.genericName}" /> 
    	    	</p:column>  
  	
        		<p:column headerText="Order Quantity" style="width:20%">  
            		<h:outputText value="#{medinvs.quantity}" />  
        		</p:column>  
  
        		<p:column headerText="Order Price" style="width:5%">  
            		<h:outputText value="#{medinvs.totalPrice}" />  
        		</p:column>  
  
  				<p:column headerText="Order Date" style="width:10%">  
            		<h:outputText value="#{medinvs.orderOpenDate}" />  
        		</p:column> 
        		 
        		<p:column headerText="Status" style="width:5%">  
            		<h:outputText value="#{medinvs.orderStatus}" />  
        		</p:column> 
        		
        		<p:column style="width:20%; text-align : center">  
                	<h:commandButton id="updateButton" action="#{orderInventoryBean.update}" value="Order" rendered="#{orderInventoryBean.action == 'order'}">  
                	<f:ajax execute="createButton" />
                	<f:setPropertyActionListener value="#{medinvs}" target="#{orderInventoryBean.orderMedication}" /> 
    				<f:param name="medicationId" value="#{medinvs.medication.medicationId}" />
    				<f:param name="action" value="#{orderInventoryBean.action}" />
            		</h:commandButton>   
            		<h:commandButton id="viewButton" action="#{orderInventoryBean.view}" value="View" rendered="#{orderInventoryBean.action == 'find'}" >  
                	<f:ajax execute="viewButton"  />
                	<f:setPropertyActionListener value="#{medinvs}" target="#{orderInventoryBean.orderMedication}" /> 
    				<f:param name="medicationId" value="#{medinvs.medication.medicationId}" />
    				<f:param name="action" value="#{orderInventoryBean.action}" />
            		</h:commandButton> 
            		<h:commandButton id="deleteButton" action="#{orderInventoryBean.delete}" value="Cancel" rendered="#{orderInventoryBean.action == 'delete'}" >  
                	<f:ajax execute="viewButton"  />
                	<f:setPropertyActionListener value="#{medinvs}" target="#{orderInventoryBean.orderMedication}" /> 
    				<f:param name="medicationId" value="#{medinvs.medication.medicationId}" />
    				<f:param name="action" value="#{orderInventoryBean.action}" />
            		</h:commandButton>
       	 		</p:column>  
    	</p:dataTable>  
    		</p:panel>
		</div>

		</h:form>

    </ui:define>
</ui:composition>
